package com.ttms.dao.impl;
import com.ttms.dao.PlayDao;
import com.ttms.pojo.Play;

import java.util.List;

public class PlayDaoImpl extends BaseDao implements PlayDao {

    @Override
    public int addPlay(Play play) {
        //language=MySQL
        String sql = "insert into play(`play_type_id`,`play_lang_id`,`play_name`,`play_introduction`,`play_image`,`play_length` ,`play_ticket_price`) values(?,?,?,?,?,?,?)";
        return update(sql, play.getPlay_type_id(),play.getPlay_lang_id(),play.getPlay_name(),play.getPlay_introduction(),play.getPlay_image(),play.getPlay_length(),play.getPlay_ticket_price());

    }

    @Override
    public int deletePlayById(Integer id) {
        //language=MySQL
        String sql = "delete from play where play_id = ?";
        return update(sql, id);
    }

    @Override
    public int updatePlay(Play play) {
//        System.out.println(" BookDaoImpl 程序在[" + Thread.currentThread().getName() + "]中");
        //language=MySQL
        String sql = "update play set `play_type_id`=?,`play_lang_id`=?,`play_name`=?,`play_introduction`=?,`play_image`=?,`play_length`=? ,`play_ticket_price`=? where play_id = ?";
        return update(sql, play.getPlay_type_id(), play.getPlay_lang_id(), play.getPlay_name(), play.getPlay_introduction(), play.getPlay_image(), play.getPlay_length(), play.getPlay_ticket_price(), play.getPlay_id());
    }

        @Override
    public Play queryPlayById(Integer id) {
            String sql = "select * from play where play_id = ?";
            return queryForOne(Play.class, sql,id);
    }

    @Override
    public List<Play> queryPlays() {
        String sql = "select `play_id`, `play_type_id`,`play_lang_id`,`play_name`,`play_introduction`,`play_image`,`play_length` ,`play_ticket_price`,`play_status` from play";
        return queryForList(Play.class, sql);
    }



    @Override
    public Integer queryForPageTotalCount() {
        String sql = "select count(*) from play";
        Number count = (Number) queryForSingleValue(sql);
        return count.intValue();
    }

    @Override
    public List<Play> queryForPageItems(int begin, int pageSize) {
        String sql = "select `play_id`, `play_type_id`,`play_lang_id`,`play_name`,`play_introduction`,`play_image`,`play_length` ,`play_ticket_price`,`play_status` from play limit ?,?";
        return queryForList(Play.class,sql,begin,pageSize);
    }

    @Override
    public List<Play> queryPlayByName(int begin, int pageSize,String name) {
        String sql = "select * from play where play_name like '%"+ name +"%' order by play_id limit ?,?";
        return queryForList(Play.class,sql,begin,pageSize);
    }

    @Override
    public Integer queryPlayCountByName(String play_name) {
        String sql = "select count(*) from play where play_name like '%"+ play_name +"%' ";
        Number count = (Number) queryForSingleValue(sql);
        return count.intValue();
    }
}
